<%-- 
    Document   : entryProductForm
    Created on : 14/04/2009, 09:59:21 AM
    Author     : Joel Chuca
--%>

<%@ include file="/common/taglibs.jsp"%>

<head>
    <title><fmt:message key="entryProductDetail.title"/></title>
    <meta name="heading" content="<fmt:message key='entryProductDetail.heading'/>"/>
    <meta name="menu" content="MaterialMenu"/>
    <!--link rel="stylesheet" type="text/css" media="all" href="styles/calendar-aqua/theme.css" /-->

    <script type="text/javascript" src="<c:url value='/scripts/calendar/calendar.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/scripts/calendar/lang/calendar-es.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/scripts/calendar/calendar-setup.js'/>"></script>

    <script type="text/javascript">
        window.onload = function() {
            Calendar.setup({
                inputField: "dateMakeID",
                ifFormat: "%d/%m/%Y",
                button: "dateMakeID"
            });

        }

        function modifyStateDiscount(){
            if(document.getElementById("withDiscount").checked){
                document.getElementById("discount").disabled =false;
            }
            else{
                document.getElementById("discount").value="";
                document.getElementById("discount").disabled=true;

            }
        }
        function modifyStateBill(){
            if(document.getElementById("withBill").checked)
                document.getElementById("codeBill").disabled =false;
            else{
                document.getElementById("codeBill").value="";
                document.getElementById("codeBill").disabled=true;
            }
        }
        function modifyStateCredit(){
            if(document.getElementById("withCredit").checked)
                document.getElementById("dateCreditID").disabled =false;
            else{
                document.getElementById("dateCreditID").value="";
                document.getElementById("dateCreditID").disabled=true;
            }
        }
    </script>
</head>

<s:form id="entryProductForm" action="saveEntryProduct" method="post" validate="true">
    <s:hidden key="entryProduct.id" cssClass="text medium"/>
    <table border="0">
        <tbody><tr>
                <c:if test="${ empty entryProduct.id  || entryProduct.deleted}">
                    <td>
                        <s:textfield key="entryProduct.date" id="dateMakeID" required="true" cssClass="text medium"/>
                    </td>
                    <td>
                        <s:select key="suppliers" list="suppliers" name="entryProduct.supplier.id" listKey="id" listValue="name"
                                  />
                    </td>
                    <td>
                        <s:select key="coins" list="coins" name="entryProduct.coin.id" listKey="id" listValue='name'
                                  />
                    </td>
                </c:if>

                <c:if test="${ (not empty entryProduct.id) && !entryProduct.deleted }">
                    <td>
                        <s:textfield key="entryProduct.date" id="dateMakeID" required="true" cssClass="text medium" disabled="true"/>
                        <s:hidden name="entryProduct.date" value="%{entryProduct.date}"/>
                    </td>
                    <td>
                        <s:select key="suppliers" list="suppliers" name="entryProduct.supplier.id" listKey="id" listValue="name"
                                  />
                        <s:hidden name="entryProduct.supplier.id" value="%{entryProduct.supplier.id}"/>
                    </td>
                    <td>
                        <s:select key="coins" list="coins" name="entryProduct.coin.id" listKey="id" listValue='name'
                                  headerKey="-1" headerValue="select" disabled="true"/>
                        <s:hidden name="entryProduct.coin.id" value="%{entryProduct.coin.id}"/>
                    </td>
                </c:if>

        </tr></tbody>
    </table>

    <table border="0">
        <tbody>
            <tr><td><fieldset>
                        <legend><fmt:message key="entryProduct.billSetting"/></legend>
                        <s:checkbox name="withBill" id="withBill"  onclick="modifyStateBill()" />
                        <label for="withBill" class="choice">Con factura</label>
                        <s:textfield key="entryProduct.bill.code" id="codeBill" required="true" cssClass="text medium" onmousemove="modifyStateBill()" />
                </fieldset></td>
            </tr>
        </tbody>
    </table>

    <li class="buttonBar bottom">
        <s:submit cssClass="button" method="save" key="button.save" theme="simple"/>
        <c:if test="${(not empty entryProduct.id) && entryProduct.deleted }">
            <s:submit cssClass="button" method="delete" key="button.delete"
                      onclick="return confirmDelete('product')" theme="simple"/>
        </c:if>
        <c:if test="${(empty entryProduct.id) || !entryProduct.deleted }">
            <s:submit cssClass="button" method="delete" key="button.delete"
                      onclick="return confirmDelete('product')" theme="simple" disabled="true"/>
        </c:if>
        <s:submit cssClass="button" method="cancel" key="button.cancel" theme="simple"/>
    </li>
</s:form>

<script type="text/javascript">
    Form.focusFirstElement($("productForm"));
</script>